﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
using System.Text;

public partial class Control_UserGroup : System.Web.UI.UserControl
{
    private Srvtools.WebDataSet WMasterGroup;
   
    public string NowChoose
    {
        set
        {
            allchoose.SelectedValue = value;
        }
        get
        {
            return allchoose.SelectedValue;
        }
    }

    public string NowChooseName
    {
        set
        {
            allchoose.SelectedItem.Text = value;
        }
        get
        {
            return allchoose.SelectedItem.Text;
        }
    }

    public void LikeReadOnlyBind(string text)
    {
        lblchoose.Text = text;

        lblchoose.Visible = true;
        allchoose.Visible = false; 
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }


    private void InitializeComponent(bool action)
    {
     System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Control_UserGroup));
        this.WMasterGroup = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMasterGroup)).BeginInit();
        // 
        // WMaster
        // 
        this.WMasterGroup.Active = true;
        this.WMasterGroup.AlwaysClose = false;
        this.WMasterGroup.PacketRecords = 100;
        this.WMasterGroup.Position = -1;
        this.WMasterGroup.RemoteName = "Common.GROUPS";
        this.WMasterGroup.ServerModify = false;
        ((System.ComponentModel.ISupportInitialize)(this.WMasterGroup)).EndInit();
    }

    public void GetGroup(bool ReadOnly, string Eid)
    {       
        if (allchoose.Items.Count <= 0)
        {
            InitializeComponent(true);
            WMasterGroup.SetWhere("GClass='2'");
            MasterGroup.DataSource = WMasterGroup;
            DataTable dt = MasterGroup.InnerDataSet.Tables[0];
    
            allchoose.Items.Clear();
            allchoose.Items.Add(new ListItem("未选择","-1"));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                allchoose.Items.Add(new ListItem(dt.Rows[i]["GROUPNAME"].ToString(), dt.Rows[i]["GROUPID"].ToString()));
            }
            object[] ret = Srvtools.CliUtils.CallMethod("SEmployees", "GetGClassTwoGroupName", new object[] { "2",Eid });

            if (ret[1] != null)
            {
                if (((DataSet)ret[1]).Tables[0].Rows.Count > 0)
                {
                    allchoose.SelectedValue = ((DataSet)ret[1]).Tables[0].Rows[0]["GROUPID"].ToString();
                    lblchoose.Text = ((DataSet)ret[1]).Tables[0].Rows[0]["GROUPNAME"].ToString();
                }
                else
                {
                    //allchoose.SelectedValue = "-1";
                    //allchoose.SelectedIndex = 0;
                    //lblchoose.Text = "未选择";
                    allchoose.SelectedValue = "-1";
                    lblchoose.Text = allchoose.SelectedItem.Text;
                }
            }
            else
            {
                //allchoose.SelectedValue = "-1";
                //allchoose.SelectedIndex = 0;
                allchoose.SelectedValue = "-1";
                lblchoose.Text = allchoose.SelectedItem.Text;
            }
        }


        if (!ReadOnly)
        {
            lblchoose.Visible = false;
            allchoose.Visible = true;           
        }
        else
        {
            lblchoose.Visible = true;
            allchoose.Visible = false; 
        }
    }


}
